<template>

    <div>
        <div id="map" ref="map"></div>
    </div>

</template>

<script>

    import "ol/ol.css";
    import Map from 'ol/Map';
    import View from 'ol/View';
    import TileLayer from 'ol/layer/Tile';
    import OSM from "ol/source/OSM";

    export default {
        name: "openlayersIndex",
        data() {
            return {
                map: null,
            }
        },
        mounted() {
            this.initMap();
        },
        methods: {
            initMap: function () {
                this.map = new Map({
                    target: "map", // 指向对象
                    layers: [
                        // 图层
                        new TileLayer({
                            // 这里定义的是平铺图层
                            source: new OSM(),
                        }),
                    ],
                    view: new View({
                        projection: "EPSG:4326",
                        center: [118.792207, 32.133476],
                        zoom: 5,

                    }),
                });
            }
        }
    }
</script>

<style  scoped>
    #map {
        width: 1000px;
        height: 600px;
    }
</style>